<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.Date" %>
<%@ page import="ut.data.User" %>
<%@ page import="ut.data.Profile" %>
<%@ page import="ut.data.Record" %>
<%@ page import="ut.data.Message" %>
<%@ page import="ut.res.Language" %>
<%@ page import="ut.util.DateTime" %>
<%
	User user = (User)session.getAttribute("user");
	if(user == null){
		response.sendRedirect("/");
		return;
	}
	
	int view = 0;
	try{
		view = Integer.parseInt(request.getParameter("view"));
	}catch(NumberFormatException e){}
	
	Profile profile = Profile.getProfile(user.id);
	Record record = Record.getRecord(user.id);
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>UT終極一翻！ | 我的個人資訊管理</title>
	<link rel="stylesheet" type="text/css" href="/style.css" media="all" />
	<link rel="stylesheet" type="text/css" href="/css/user-info.css" media="all" />
	<script type="text/javascript" src="/js/Utility.js"></script>
	<script type="text/javascript" src="/js/Message.js"></script>
	<script type="text/javascript" src="/js/Ajax.js"></script>
	<script type="text/javascript" src="/js/Button.js"></script>
	<script type="text/javascript" src="/js/Account.js"></script>
	<script type="text/javascript" src="/script.js"></script>
</head>
<body onload="init();">
<%@ include file="/include/banner.jsp" %>
	<div class="content">
		<div class="title" style="margin-bottom:60px">我的個人資訊管理</div>
<%
	if(view == 0){
%>
<!--基本資料-->
		<div class="profile block">
			<div>
<%
	if(newMsgCount == 0){
%>
				<span class="tab current">基本資料</span>
<%	
	}else{
%>
				<span class="tab current">基本資料 <span class="alert"><%= newMsgCount %></span></span>
<%
	}
%>
				<span class="tab blue"><a class="link-tab" href="/account/user-info.jsp?uid=<%= user.id %>&view=1">發案紀錄</a></span>
				<span class="tab green"><a class="link-tab" href="/account/user-info.jsp?uid=<%= user.id %>&view=2">譯者資料＆接案紀錄</a></span>
			</div>
			<div class="toolbar">
				<span class="tool js" onclick="Account.PasswordChange.show();">更改密碼</span>
<%
	if(user.verify == 0){
%>
				<span class="tool js" onclick="Account.verifyEmail();">重發驗證信</span>
<%
	}else{
		if(user.notify){
%>
				<span class="tool js" onclick="Account.changeNotify(false);">關閉 E-Mail 通知</span>
<%
		}else{
%>
				<span class="tool js" onclick="Account.changeNotify(true);">開啟 E-Mail 通知</span>
<%
		}
	}
	if(user.verify == 1){
%>
				<span class="tool"><a class="tool" href="/account/verify-phone.jsp">驗證手機</a></span>
<%
	}
%>

<%
	if(newMsgCount == 0){
%>
				<span class="tool"><a class="tool" href="/account/message.jsp">我的訊息匣</a></span>
<%
	}else{
%>
				<span class="tool"><a class="tool" href="/account/message.jsp">我的訊息匣<span class="alert"><%= newMsgCount %></span></a></span>
<%
	}
%>
				<span class="tool"><a class="tool" href="/account/favorite.jsp">我的關注列表</a></span>
<%
	if(user.verify == 0){
%>
				<span class="tool js" 
					onclick="Message.show('access denied: deposit', 400, '權限不足', '請先通過 E-Mail 驗證以使用此功能', Message.BUTTON_OK)">儲值</span>
				<span class="tool js" 
					onclick="Message.show('access denied: withdraw', 400, '權限不足', '請先通過 E-Mail 驗證以使用此功能', Message.BUTTON_OK)">提款</span>
<%
	}else{
%>
				<span class="tool"><a class="tool" href="/account/deposit.jsp">儲值</a></span>
				<span class="tool"><a class="tool" href="/account/withdraw.jsp">提款</a></span>
<%
	}
%>
				<span class="tool"><a class="tool" href="/account/transaction.jsp">交易紀錄</a></span>
			</div>
			<div class="profile-content">
				<div class="profile-element">
					<div class="profile-element-left">名稱：</div>
					<div class="profile-element-right"><%= user.name %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">E-Mail：</div>
					<div class="profile-element-right">
<%
	out.println(user.email);
	if(user.verify == 0){
%>
					<span class="mark-red comment">
						　<img src="/image/error.png" width="14px" class="middle" /> 未通過驗證
					</span>
<%
	}else{
%>
					<span class="mark-green comment">
						　<img src="/image/ok.png" width="14px" class="middle" /> 已通過驗證
					</span>
<%
	}
%>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">手機：</div>
					<div class="profile-element-right">
<%
	if(user.phone.equals("")){
%>
					尚未提供手機
					<span class="mark-red comment">
						　<img src="/image/error.png" width="14px" class="middle" /> 未通過驗證
					</span>
<%
	}else{
		if(user.verify != 2){
%>
					<%= user.phone %>
					<span class="mark-red comment">
						　<img src="/image/error.png" width="14px" class="middle" /> 未通過驗證
					</span>
<%
		}else{
%>
					<%= user.phone %>
					<span class="mark-green comment">
						　<img src="/image/ok.png" width="14px" class="middle" /> 已通過驗證
					</span>
<%
		}
	}
%>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">帳戶餘額：</div>
					<div class="profile-element-right">
						NTD <%= user.money %> 元　
						<button class="button" onclick="Account.updateUser();" 
							style="font-size:14px;padding:1px 6px;margin:0px;height:25px;line-height:14px;"
							onmousedown="this.style.borderStyle='inset';"
							onmouseup="this.style.borderStyle='outset';"
							onmouseout="this.style.borderStyle='outset';">
							<img src="/image/refresh.png" width="14px" class="middle" />
							<span class="mark-red comment">更新</span>
						</button>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">註冊時間：</div>
					<div class="profile-element-right"><%= DateTime.toDateTime(user.joinTime) %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">最後登入時間：</div>
					<div class="profile-element-right"><%= DateTime.toDateTime(user.loginTime) %></div>
				</div>
				<div style="clear:both"></div>
			</div>
		</div>
<%
	}else if(view == 1){
%>
<!--發案者資料-->
		<div class="profile block">
			<div>
				<span class="tab"><a class='link-tab' href="/account/user-info.jsp?uid=<%= user.id %>&view=0">基本資料</a></span>
				<span class="tab blue current">發案紀錄</span>
				<span class="tab green"><a class='link-tab' href="/account/user-info.jsp?uid=<%= user.id %>&view=2">譯者資料＆接案紀錄</a></span>
			</div>
			<div class="toolbar blue">
				<a class="tool" href="/free-task/free-task-list-member.jsp?uid=<%= user.id %>&type=employer">免費發案列表</a>
				<a class="tool" href="/task/task-list-member.jsp?type=employer">付費發案管理</a>
			</div>
			<div class="profile-content">
				<div class="profile-element">
					<div class="profile-element-left">免費案件發案數：</div>
					<div class="profile-element-right"><%= record.freeTask %></div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">付費案件發案數：</div>
					<div class="profile-element-right"><%= record.task %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件成功數：</div>
					<div class="profile-element-right"><%= record.taskSuccess %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件綜合評價：</div>
					<div class="profile-element-right">
<%
		if(record.taskScoreNumber == 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
<%
		}else{
			double score = record.taskScore / record.taskScoreNumber;
			for(int i = 1; i <= 5; i++){
				if(score >= 1){
%>
						<img src="/image/star-2.png" class="image-middle" />
<%
				}else if(score < 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
<%
				}else{
%>
						<img src="/image/star-1.png" class="image-middle" />
<%
				}
				score--;
			}
		}
%>
						<span class="mark-green comment">（已有 <%= record.taskScoreNumber %> 人評價）</span>
					</div>
				</div>
				<div style="clear:both"></div>
			</div>
		</div>
<%
	}else{
%>
<!--譯者資料-->
		<div class="profile block">
			<div>
				<span class="tab"><a class='link-tab' href="/account/user-info.jsp?uid=<%= user.id %>&view=0">基本資料</a></span>
				<span class="tab blue"><a class='link-tab' href="/account/user-info.jsp?uid=<%= user.id %>&view=1">發案紀錄</a></span>
				<span class="tab green current">譯者資料＆接案紀錄</span>
			</div>
<%
		if(profile == null){
%>
			<div class="toolbar green">
<%
			if(user.verify == 0){
%>
				<span class="tool js" onclick="Account.ProfileCreate.show(-1)">建立譯者資料</span>
<%
			}else{
%>
				<span class="tool js" onclick="Account.ProfileCreate.show()">建立譯者資料</span>
<%
			}
%>
			</div>
			<div id="profile-content" class="block-center">您必須先建立譯者資料才可以在本站接案。</div>
<%
		}else{
			String specFromLang = "";
			String specToLang = "";
			Language fromLang = null;
			Language toLang = null;
			String spec = "";
			for(int i = 0; i < profile.specialties.length; i++){
				fromLang = Language.getLanguage(profile.specialties[i][0]);
				toLang = Language.getLanguage(profile.specialties[i][1]);
				spec += "<div>";
				spec += "自<span class='spec-lang mark-red'>" + fromLang.title + "</span>";
				spec += "翻譯至<span class='spec-lang mark-red'>" + toLang.title + "</span>";
				spec += "</div>";
				
				if(i != profile.specialties.length - 1){
					specFromLang += fromLang.id + "," + fromLang.title + ";";
					specToLang += toLang.id + "," + toLang.title + ";";
				}else{
					specFromLang += fromLang.id + "," + fromLang.title;
					specToLang += toLang.id + "," + toLang.title;
				}
			}
%>
			<div class="toolbar green">
				<span class="tool js" 
					onclick="Account.ProfileCreate.show();Account.ProfileCreate.setValue('<%= profile.description %>', '<%= profile.education %>', '<%= profile.certification %>', '<%= profile.experience %>', '<%= specFromLang %>', '<%= specToLang %>');">
					修改譯者資料</span>
				<a class="tool" href="/free-task/free-task-list-member.jsp?uid=<%= user.id %>&type=translator">免費接案列表</a>
				<a class="tool" href="/task/task-list-member.jsp?&type=translator">付費接案管理</a>
			</div>
			<div id="profile-content" class="profile-content">
				<div class="profile-element">
					<div class="profile-element-left">翻譯專長：
					</div>
					<div class="profile-element-right"><%= spec %></div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">免費案件翻譯數：</div>
					<div class="profile-element-right"><%= record.freeResponse %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">免費案件最佳翻譯數：</div>
					<div class="profile-element-right"><%= record.freeSuccess %></div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">付費案件接案數：</div>
					<div class="profile-element-right"><%= record.response %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件成功數：</div>
					<div class="profile-element-right"><%= record.success %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件綜合評價：</div>
					<div class="profile-element-right">
<%
		if(record.scoreNumber == 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
<%
		}else{
			double score = record.score / record.scoreNumber;
			for(int i = 1; i <= 5; i++){
				if(score >= 1){
%>
						<img src="/image/star-2.png" class="image-middle" />
<%
				}else if(score <= 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
<%
				}else{
%>
						<img src="/image/star-1.png" class="image-middle" />
<%
				}
				score--;
			}
		}
%>
						<span class="mark-green comment">（已有 <%= record.scoreNumber %> 人評價）</span>
					</div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">自我介紹：</div>
					<div class="profile-element-right"><%= profile.description %></div>
				</div>
				<div style="clear:both"></div>
				<div class="profile-element">
					<div class="profile-element-left">學歷：</div>
					<div class="profile-element-right"><%= profile.education %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">語言相關證照：</div>
					<div class="profile-element-right"><%= profile.certification %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">工作經歷：</div>
					<div class="profile-element-right"><%= profile.experience %></div>
				</div>
				<div style="clear:both"></div>
			</div>
<%
		}
%>
			<form id="profile-create" class="profile-create" onsubmit="Account.ProfileCreate.create(this);return false;">
				<div class="profile-element">
					<div class="profile-element-left">翻譯專長：</div>
					<div id="profile-create-spec" class="profile-element-right">
						<div id="profile-create-spec-selector" class="profile-element">
							<div class="profile-element-left profile-spec-left">
								從
								<select name="fromLang">
<%
		Language[] langs = Language.getLanguages();
		for(int i = 0; i < langs.length; i++){
			out.println("<option value='" + langs[i].id + "'>" + langs[i].title + "</option>");
		}
%>
								</select>
								翻譯至
								<select name="toLang">
<%
		for(int i = 0; i < langs.length; i++){
			out.println("<option value='" + langs[i].id + "'>" + langs[i].title + "</option>");
		}
%>
								</select>
							</div>
							<div class="profile-element-right profile-spec-right">
								<input type="button" value="新增" class="input-button" onclick="Account.ProfileCreate.addSpec();" />
							</div>
						</div>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left profile-margin">
						自我介紹：<br/>
						<div class="mark-red comment">＊限 255 字</div>
					</div>
					<div class="profile-element-right profile-margin">
						<textarea name="description"></textarea>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left profile-margin">
						學歷：<br/>
						<div class="mark-red comment">＊限 255 字</div>
					</div>
					<div class="profile-element-right profile-margin">
						<textarea name="education"></textarea>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left profile-margin">
						語言相關證照：<br/>
						<div class="mark-red comment">＊限 255 字</div>
					</div>
					<div class="profile-element-right profile-margin">
						<textarea name="certification"></textarea>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left profile-margin">
						工作經歷：<br/>
						<div class="mark-red comment">＊限 255 字</div>
					</div>
					<div class="profile-element-right profile-margin">
						<textarea name="experience"></textarea>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left profile-create-button-left">
						<input name="submit" type="submit" class="button green" value="建立"
							onmousedown="this.style.borderStyle='inset';"
							onmouseup="this.style.borderStyle='outset';"
							onmouseout="this.style.borderStyle='outset';" />
					</div>
					<div class="profile-element-left profile-create-button-right">
						<button type="button" class="button green"
							onmousedown="this.style.borderStyle='inset';"
							onmouseup="this.style.borderStyle='outset';"
							onmouseout="this.style.borderStyle='outset';"
							onclick="Account.ProfileCreate.hide();">
							取消
						</button>
					</div>
				</div>
				<div style="clear:both"></div>
			</form>
		</div>
<%
	}
%>
		<div class="block" style="text-align:center;margin-top:50px;padding:20px 0px;">
			<img src="/image/cash-flow.png" />
		</div>
<%@ include file="/include/foot.jsp" %>
	</div>
</body>
</html>